package com.hudongwx.food.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hudongwx.food.R;
import com.hudongwx.food.utils.MyJsonObject;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

public class TiaoZhuanZhuanTiActivity extends AppCompatActivity {

    @ViewInject(R.id.zhuanti_rec)
    private RecyclerView recyclerView;
    @ViewInject(R.id.zhuanti_rec1)
    private RecyclerView recyclerView1;
    private  Intent intent;
    private int type;
    private MyZhuanTiAdapter myZhuanTiAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tiao_zhuan_zhuan_ti);
    }

    class MyZhuanTiAdapter extends RecyclerView.Adapter<MyZhuanTiViewHolder>{
        JSONArray array;
        public MyZhuanTiAdapter(JSONArray array) {
            this.array = array;
        }
        public void updataArray(JSONArray array){
            this.array=array;
            notifyDataSetChanged();
        }

        @Override
        public MyZhuanTiViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return null;
        }

        @Override
        public void onBindViewHolder(MyZhuanTiViewHolder holder, int position) {

        }

        @Override
        public int getItemCount() {
            return 0;
        }
    }

    class MyZhuanTiViewHolder extends RecyclerView.ViewHolder{
        TextView tv1,tv2,tv3;
        ImageView iv ;
        public MyZhuanTiViewHolder(View itemView) {
            super(itemView);
            tv1 = (TextView) findViewById(R.id.zhuanti_biaoti);
            tv2 = (TextView) findViewById(R.id.zhuanti_shijian);
            tv3 = (TextView) findViewById(R.id.zhuanti_shuoming);
            iv = (ImageView) findViewById(R.id.zhuanti_tupian);
        }
    }
    public void getItem(){
        intent = getIntent();
        type = intent.getIntExtra("type", 0);
        RequestParams params=new RequestParams("http://api.shiandianping.com/api/sourceAndroidDianPing/v3.1.0/Posts?postId="+type);
        x.http().get(params, new Callback.CommonCallback<MyJsonObject>() {
            @Override
            public void onSuccess(MyJsonObject result) {
                try {
                    JSONObject data = result.getJSONObject("Data");
//                    myZhuanTiAdapter.updataArray(data);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
